<?php
/**
 * @purpose: 对“通知”类型中子类型为10(转载推他)的编码与解码文件
 * @author: Mandel Woo <wuzhijian@snda.com>

 * @memo: 参阅母板文件
 */
require_once(dirname(__FILE__)."/../../../models/user/UCModUserInfo.php");


function msg_notice_type10_encoder() {
	$fields = array("user_id", "comment", "twitter", "mood_id", "twitter_owner_id");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	/*
	｛转推人的昵称｝转推了你的推他：｛转推人在转推时的评论｝
	｛被转推的原推的前50个字节（带链接）｝
	*/
	return serialize(array(
			"user_id"          => $user_id,
			"comment"          => utf_substr($comment, 150),
			"twitter"          => utf_substr($twitter, 100),
			"mood_id"          => $mood_id,
			"twitter_owner_id" => $twitter_owner_id,
			));
}

function msg_notice_type10_decoder() {
	$fields = array("id","receiverid","content","createTime","changeFlag","fmt");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	/*
	｛转推人的昵称｝转推了你的推他：｛转推人在转推时的评论｝
	｛被转推的原推的前50个字节（带链接）｝
	*/

	$data    = unserialize($content);
	$user_id = $data['user_id'];
	$comment = codeToSmile(nl2br(htmlspecialchars($data['comment'])));
	$twitter = codeToSmile(htmlspecialchars($data['twitter']));
	$mood_id = $data['mood_id'];
	$twitter_owner_id = $data['twitter_owner_id'];

	$user_info = UCModUserInfo::getUserInfo($user_id, array(USERINFO_NICKNAME));
	$nickname  = $user_info[USERINFO_NICKNAME];
	$nickname  == '' && $nickname = $user_id; #取不到昵称
	$nickname = htmlspecialchars($nickname);

	$user = "<a href=\"".get_user_home_url($user_id)."\" target='_blank'>{$nickname}</a>";


	if ($fmt == 'line') {
		return sprintf("%s转推了你的推他", $user);

	} else if ($fmt == 'box') {
		if (empty($comment)) { //nothing
		} else {
			$comment = "：" . $comment;
		}

		$twitter = sprintf("<a href=\"/tuita/viewdetail/mood_id/%s/user_id/%d\" target=\"_blank\">%s</a>", $mood_id, $twitter_owner_id, $twitter);

		$space = "&nbsp;&nbsp;&nbsp;&nbsp;";

		$html = "{$user}转推了你的推他。<br /><br />{$space}<strong>推它原文：</strong><br />{$space}“　{$twitter}　”<br /><br />";

		if (empty($comment)) { //nothing
		} else {
			$html .= "{$space}<strong>转推内容：</strong><br />{$space}".ltrim($comment,"：");
		}

		return '<div class="font14">' . $html . '</div>';

	} else {
		return '';
	}
}

